package com.margo.project.sentinel;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

public class SentinelClient {
	public static void main(String[] args) throws InterruptedException, ExecutionException {
		RestTemplate restTemplate=new RestTemplate();
		
		ExecutorService executorService=Executors.newFixedThreadPool(8);
//		ThreadPoolExecutor threadPoolExecutor=
//		new ThreadPoolExecutor(8, 8,
//                0L, TimeUnit.MILLISECONDS,
//                new LinkedBlockingQueue<Runnable>());
//		threadPoolExecutor.
		for(int i=0;i<25;i++) {
			Future<String> future=executorService.submit(new Callable<String>() {

				@Override
				public String call() throws Exception {
					HttpHeaders headers=new HttpHeaders();
					//请求体
					MultiValueMap<String, Object> body=new LinkedMultiValueMap<String, Object>();
					HttpEntity<MultiValueMap<String, Object>> httpEntity=
							new HttpEntity<MultiValueMap<String,Object>>(body, headers);
					return restTemplate.postForObject("http://localhost:8080/getOrder?orderId=111",httpEntity ,String.class);
				}
				
			});	
			if(future.isDone()) {
				System.out.println(future.get());
			}

		}
	}
}
